package com.ostrich.lib_common.base;

import android.content.Intent;
import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ostrich.lib_common.R;

/**
 *
 * fragment懒加载：只有当前
 * @param <VDB>
 */

public abstract class BaseFragment<VDB extends ViewDataBinding> extends Fragment {
    protected VDB binding;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        binding = DataBindingUtil.inflate(inflater,bindLayout(),container,false);
        initView();
        initListener();
        return binding.getRoot();
    }
    //懒加载
    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    public abstract int bindLayout();
    public  abstract void initView();
    public abstract void initData();
    public abstract void initListener();


    //页面跳转
    public void startActivity(Class class_){
        Intent intent = new Intent(getActivity(), class_);
        startActivity(intent);
    }

    //页面跳转传值
    public void startActivityBundle(Class class_,Bundle bundle){
        Intent intent = new Intent(getActivity(), class_);
        intent.putExtras(bundle);
        startActivity(intent);
    }
    //.............

}